package com.atguigu.edu.controller;


import com.atguigu.edu.entity.subject.OneSubject;
import com.atguigu.edu.service.SubjectService;
import com.atguigu.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author ld
 * @since 2022-08-15
 */
@RestController
@Api(description="课程分类管理")
@RequestMapping("/eduservice/subject")
//@CrossOrigin
public class SubjectController {

    @Resource
    private SubjectService subjectService;
    //添加课程分类
    //获取上传过来的文件，把内容读取出来，就不用上传到服务器
    @ApiOperation(value = "Excel批量导入")
    @PostMapping("/add")
    public R addSubject(MultipartFile file){
        subjectService.addSubject(file,subjectService);
        return R.ok();
    }
    @ApiOperation(value = "tree展示课程分类")
    @GetMapping("/list")
    public R listByTree(){
        List<OneSubject> list=subjectService.listByTree();
        return R.ok().data("list",list);
    }
}

